﻿@model MyMainSite2.UI.AdminWeb.Models.Admin.LoginModel

@section ScriptLoad {

    loadJavaScript();
}

<script type="text/javascript">

    function loadJavaScript() {

        $("#divLoginLoading").hide();

        $("#textUserName, #textPassword").keypress(function (e) {

            if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {

                $("#buttonLogin").click();
            }
        });

        $("#buttonLogin").click(function () {

            clearErrors();

            var userName = $("#textUserName").val().trim();
            var password = $("#textPassword").val().trim();

            if (userName.length <= 0) {

                addError("Please enter a User Name.");
            }

            if (password.length <= 0) {

                addError("Please enter a Password.");
            }

            var hasErrors = showErrors();

            if (!hasErrors) {

                doLogin();
            }
        });
    }

    function doLogin() {

        $("#divLoginLoading").show();
        $("#buttonLogin").hide();

        ajaxRequest("/admin/dologin",
            {
                userName: $("#textUserName").val(),
                password: $("#textPassword").val()
            },
            function (data) {

                window.location = "@this.Request.Params["ReturnUrl"]";
            },
            function (message) {

                $("#divLoginLoading").hide();
                $("#buttonLogin").show();
            });
    }

</script>

<article class="module width_3_quarter">
    <header>
        <h3>Login</h3>
    </header>
    <div class="module_content">
        <fieldset>
            <legend></legend>
            <label for="textUserName">
                User Name:
            </label>
            <input id="textUserName" type="text" />
        </fieldset>
        <fieldset>
            <legend></legend>
            <label for="textPassword">
                Password:
            </label>
            <input id="textPassword" type="password" />
        </fieldset>
    </div>
    <footer>
        <div class="submit_link">
            <div id="divLoginLoading" class="loading"></div>
            <input id="buttonLogin" type="button" class="alt_btn" value="Login" />
        </div>
    </footer>
</article>